/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.crm.cs.web.MustInquireAction
   Module Description   :

   Date Created      : 2010/1/21
   Original Author   : andy.chuang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.crm.cs.web;

import java.util.Date;

import javax.annotation.Resource;

import com.yaodian100.core.admin.utils.AdminHelper;
import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.crm.cs.entity.CommonQuestionType;
import com.yaodian100.crm.cs.entity.MustInquire;
import com.yaodian100.crm.cs.entity.MustInquireAnswer;

/**
 * @author andy.chuang
 *
 */
public class MustInquireAction {
    private String id;
    private String commonQuestionTypeId;
    private String miId;
    private String description;
    private String iamlazy;
    private String AJAX;
    @Resource
    private BaseManager baseMgr;
    public String page(){
	if(AJAX!=null && AJAX.equals("true")){
	    return iamlazy+"_ajax";
	}else{
	    return iamlazy;
	}
    }
    private String returnPage(String orgPage){
	if(AJAX!=null && AJAX.equals("true")){
	    return orgPage+"_ajax";
	}else{
	    return orgPage;
	}
    }
    public String updateMustInquire(){
	MustInquire mi=null;
	Date date=new Date();
	if(id!=null && id.length()>0){
	    mi=(MustInquire)baseMgr.get(MustInquire.class, Long.parseLong(id));
	    
	}else{
	    mi=new MustInquire();
	    mi.setCreateDate(date);
	    mi.setCreateUser(AdminHelper.getUserDetails().getUsername());
	}
	if(commonQuestionTypeId!=null && commonQuestionTypeId.length()>0){
	    CommonQuestionType cqt=new CommonQuestionType();
	    cqt.setId(commonQuestionTypeId);
	    mi.setCommonQuestionType(cqt);
	}
	mi.setModifyUser(AdminHelper.getUserDetails().getUsername());
	mi.setDescription(description);
	baseMgr.saveOrUpdate(mi);
	return returnPage("updateMustInquire");
    }
    public String deleteMustInquire(){
	if(id!=null && id.length()>0){
	    MustInquire mi=(MustInquire)baseMgr.get(MustInquire.class, Long.parseLong(id));
	    baseMgr.delete(mi);
	}
	return returnPage("deleteMustInquire");
    }
    public String updateAnswer(){
	MustInquireAnswer mia=null;
	if(id!=null && id.length()>0){
	    mia=(MustInquireAnswer)baseMgr.get(MustInquireAnswer.class, Long.parseLong(id));
	    
	}else{
	    mia=new MustInquireAnswer();
	    mia.setCreateDate(new Date());
	    mia.setCreateUser(AdminHelper.getUserDetails().getUsername());
	}
	if(miId!=null && miId.length()>0){
	    MustInquire mi=new MustInquire();
	    mi.setId(Long.parseLong(miId));
	    mia.setMustInquire(mi);
	}
	mia.setModifyUser(AdminHelper.getUserDetails().getUsername());
	mia.setDescription(description);
	baseMgr.saveOrUpdate(mia);
	return returnPage("updateAnswer");
    }
    public String deleteAnswer(){
	if(id!=null && id.length()>0){
	    MustInquireAnswer mia=(MustInquireAnswer)baseMgr.get(MustInquireAnswer.class, Long.parseLong(id));
	    baseMgr.delete(mia);
	}
	return returnPage("deleteAnswer");
    }
    /**
     * @return the id
     */
    public String getId() {
        return id;
    }
    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }
    /**
     * @return the commonQuestionTypeId
     */
    public String getCommonQuestionTypeId() {
        return commonQuestionTypeId;
    }
    /**
     * @param commonQuestionTypeId the commonQuestionTypeId to set
     */
    public void setCommonQuestionTypeId(String commonQuestionTypeId) {
        this.commonQuestionTypeId = commonQuestionTypeId;
    }
    /**
     * @return the iamlazy
     */
    public String getIamlazy() {
        return iamlazy;
    }
    /**
     * @param iamlazy the iamlazy to set
     */
    public void setIamlazy(String iamlazy) {
        this.iamlazy = iamlazy;
    }
    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }
    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
    /**
     * @return the miId
     */
    public String getMiId() {
        return miId;
    }
    /**
     * @param miId the miId to set
     */
    public void setMiId(String miId) {
        this.miId = miId;
    }
    /**
     * @return the aJAX
     */
    public String getAJAX() {
        return AJAX;
    }
    /**
     * @param aJAX the aJAX to set
     */
    public void setAJAX(String aJAX) {
        AJAX = aJAX;
    }
}
